package com.liuhw.learnview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by liuhw on 2017/8/8.
 * 自定义圆形
 */
@SuppressWarnings("unused")
public class CircleView extends View {

    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public CircleView(Context context) {
        super(context);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setColor(Color.RED);
        // 绘制一个实心圆
        canvas.drawCircle(50, 50, 50, mPaint);
        // 绘制一个环形
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);
        canvas.drawCircle(200 + mPaint.getStrokeWidth() / 2, 100 + mPaint.getStrokeWidth() / 2, 100, mPaint);
        // 绘制一个空心矩形
        canvas.drawRect(305, 305, 495, 395, mPaint);
        // 绘制一个实心矩形
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(505, 300, 705, 400, mPaint);
        // 绘制圆点
        mPaint.setStrokeWidth(20);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawPoint(100, 200, mPaint);
    }
}
